Skip to content
This repository was archived by the owner on Aug 17, 2026. It is now read-only.

fix: PromptBus wrapper-recapture crash + TUI auto-cancel (#136) - #145

Merged
joeshull merged 1 commit into
mainfrom
fix/136-pristine-originals
Aug 14, 2026
Merged

fix: PromptBus wrapper-recapture crash + TUI auto-cancel (#136)#145
joeshull merged 1 commit into
mainfrom
fix/136-pristine-originals

Conversation

@joeshull

Copy link
Copy Markdown

Summary

Fixes two ask-tool bugs in the extension bridge.

Bug 1: RangeError crash (#136)

WeakMap miss in isolated vm context captures wrapper as "original" — infinite recursion.

Fix: getOrCreatePristineOriginals unwraps via __pristineOriginal stash (carried on each wrapper by bridge.ts). Never stores a wrapper as originals. Cycle-guarded.

Bug 2: Fresh-session ask immediately cancelled

TUI adapter's native ctx.ui.select is an RPC no-op returning undefined instantly — races dashboard with spurious cancelled: true.

Fix: TUI adapter checks bus.hasComponentClaim(id). When dashboard holds a component claim, it suppresses the auto-cancel and lets the dashboard handle the prompt.

Changes

File Change
ctx-ui-originals.ts unwrapPristine() with __pristineOriginal stash recovery
bridge.ts Stash __pristineOriginal on wrappers; TUI adapter hasComponentClaim gate
prompt-bus.ts Added hasComponentClaim(id) method
Test file Updated warn assertion + 2 regression tests for unwrap semantics

Verification

@joeshull
joeshull enabled auto-merge (squash) August 14, 2026 19:03
…e wrapper as original (#136)

- Added unwrapPristine() to ctx-ui-originals: walks wrapper chain through
  __pristineOriginal stash (carried on the wrapper itself), never stores a
  PromptBus wrapper as an original. Back-fills stash on recovery so future
  captures in fresh vm contexts unwrap directly.
- Added __pristineOriginal stashes on all bridge.ts wrappers (select, input,
  confirm, editor, notify) so the true native is reachable even when the
  process-parked WeakMap misses (isolated extension vm contexts).
- Added hasComponentClaim() to PromptBus so the TUI adapter can detect when
  the dashboard is rendering the prompt and suppress an auto-cancel from a
  no-op native method (RPC-mode stub that returns undefined immediately).
- TUI adapter present(): when the native ui method returns undefined AND the
  bus has a dashboard component claim, let the dashboard handle the prompt
  instead of winning the race with a spurious cancellation.
- Updated regression tests; added explicit coverage for unwrap recovery and
  never-store-wrapper semantics.
@joeshull
joeshull force-pushed the fix/136-pristine-originals branch from fd1d3cd to f61948a Compare August 14, 2026 19:24
@joeshull
joeshull merged commit ce42f1b into main Aug 14, 2026
3 of 4 checks passed
@joeshull
joeshull deleted the fix/136-pristine-originals branch August 14, 2026 19:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PromptBus TUI originals recaptured as wrappers after jiti reload → infinite onRequest cycle

1 participant